# FindBullet.cmake
#
# Copyright 2010 Johan Waldeback
# This file is released under GPL v3 lisence
#
# sets variables:
# OgreBullet_ROOT
# OgreBullet_INCLUDE_DIRS
# OgreBullet_LIBRARY_DIRS
# OgreBullet_LIBRARIES
# OgreBullet_LIBRARIES_DEBUG
#

# USAGE: 
#  find_package( OgreBullet COMPONENTS Collisions Dynamics REQUIRED )
#  include_directories(${OgreBullet_INCLUDE_DIRS})
#  link_directories(${OgreBullet_LIBRARY_DIRS})
#  add_executable( MyApp ... )
#  TARGET_LINK_LIBRARIES( MyApp optimized ${OgreBullet_LIBRARIES}  )
#  TARGET_LINK_LIBRARIES( MyApp debug ${OgreBullet_LIBRARIES_DEBUG}  )
#


#
# macro OGREBULLET_ERROR_MESSAGE - prints an error message
#
# If required, then error messages becomes fatal errors
# If not required, then error messages becomes status messages
#
macro( OGREBULLET_ERROR_MESSAGE _msg )
  if( OGREBULLET_FIND_REQUIRED )
    message( FATAL_ERROR ${_msg} )
  else()
    message( STATUS ${_msg} )
  endif()
endmacro()

#
# macro OGREBULLET_STATUS_MESSAGE - prints an status message
#
# If not quiet - prints a status message
# If quiet - prints nothing
#
macro( OGREBULLET_STATUS_MESSAGE _msg )
  if(NOT OGREBULLET_FIND_QUIET )
    message( STATUS ${_msg} )
  endif()
endmacro()

#
# Find the OgreBullet_ROOT
#

# If OGREBULLET_ROOT was defined in the environment, use it.
find_path( OgreBullet_ROOT NAMES Collosions/include/OgreBulletCollisions.h Dynamics/include/OgreBulletDynamics.h 
  PATHS
    $ENV{OGREBULLET_ROOT}
    "C:/OgreBullet_r2964"
)

#print status message
message( STATUS "OgreBullet root dir: ${OgreBullet_ROOT}" )


SET(OgreBullet_FOUND TRUE)

#
# Find the include dir
#
foreach( COMPONENT ${OgreBullet_FIND_COMPONENTS} )
  set( _path "_path-NOTFOUND" )
  find_path( _path NAMES "OgreBullet${COMPONENT}.h"
  PATHS
    ${OgreBullet_ROOT}/${COMPONENT}/include
  )
  
  
  IF("${_path}" STREQUAL "_path-NOTFOUND")
    OGREBULLET_STATUS_MESSAGE("OgreBullet - OgreBullet${COMPONENT}.h : * NOT FOUND *")
    SET(OgreBullet_FOUND FALSE)
  else()
    OGREBULLET_STATUS_MESSAGE("OgreBullet - OgreBullet${COMPONENT}.h : ${_path}")
    LIST(FIND "${_path}" OgreBullet_INCLUDE_DIRS _found )
    if( _found LESS 0 )
      SET( OgreBullet_INCLUDE_DIRS ${OgreBullet_INCLUDE_DIRS} "${_path}" )
    endif()
  endif()

endforeach()

OGREBULLET_STATUS_MESSAGE("OgreBullet include dirs: ${OgreBullet_INCLUDE_DIRS}")

#
# Find library dirs
#
# todo: better
SET( OgreBullet_LIBRARY_DIRS "${OgreBullet_ROOT}/lib" )

OGREBULLET_STATUS_MESSAGE("OgreBullet library dirs: ${OgreBullet_LIBRARY_DIRS}")


#
# Find Libraries
#
# todo: better

FOREACH( COMPONENT ${OgreBullet_FIND_COMPONENTS} )
  LIST(FIND "OgreBullet${COMPONENT}.lib" OgreBullet_LIBRARIES _found)
  IF( _found LESS 0)
    SET( OgreBullet_LIBRARIES ${OgreBullet_LIBRARIES} "OgreBullet${COMPONENT}.lib" )
  ENDIF()

  LIST(FIND "OgreBullet${COMPONENT}_d.lib" OgreBullet_LIBRARIES_DEBUG _found)
  IF( _found LESS 0)
    SET( OgreBullet_LIBRARIES_DEBUG ${OgreBullet_LIBRARIES_DEBUG}  "OgreBullet${COMPONENT}_d.lib" )
  ENDIF()
ENDFOREACH()

OGREBULLET_STATUS_MESSAGE("OgreBullet libraries: ${OgreBullet_LIBRARIES}")
OGREBULLET_STATUS_MESSAGE("OgreBullet libraries (debug): ${OgreBullet_LIBRARIES_DEBUG}")
OGREBULLET_STATUS_MESSAGE("OgreBullet found: ${OgreBullet_FOUND}")

